package com.paobuji.aidebao.myapplication.tool;

import android.app.Activity;
import android.content.SharedPreferences;

import com.paobuji.aidebao.myapplication.application.MyApplication;


/**
 * Created by Lijianbao on 2018/6/30.
 */

public class SpUtil {
    /**
     * 本地preferences配置文件名称
     */
    public final static String SP_NAME = "demo";
    /**
     * 当前语言版本
     */
    public final static String LANGUAGE = "app_language";
    public final static int ENG = 0;
    public final static int ZH = 1;

    public static void setBoolean(String key, boolean value) {
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putBoolean(key, value);
        edit.apply();
    }

    public static boolean getBoolean(String key) {
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        return sharedPreferences.getBoolean(key, false);
    }

    public static void setInt(String name, int value) {
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putInt(name, value);
        edit.apply();
    }

    public static int getInt(String key) {
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        int value = sharedPreferences.getInt(key, -1);
        return value;
    }

    /**
     * @param name
     * @param str
     */
    public static void setString(String name, String str){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString(name,str);
        edit.apply();
    }
    /**
     * @param name
     */
    public static String getString(String name){
        SharedPreferences sharedPreferences = MyApplication.getInstance().getSharedPreferences(SP_NAME, Activity.MODE_PRIVATE);
        return sharedPreferences.getString(name,"");
    }
}
